// pages/user/user.js
const footer = require('../footer/footer.js');
const app = getApp();
Page({
  /**
   * 组件的初始数据
   */
  data: {
    isSelect: '4',
    userInfo:[],
    ReUser: true,
    ReUserName:true,
    ReValue:"",
    ReKey:"",
    RePassValue:"",
  },
  pageReSetClick: function (params) {
    footer.pageReSetClick(params)
  },
  valuechange: function (params) {
    this.setData({
      ReValue: params.detail.value
    })
  },
  RePassValueChange: function (params) {
    this.setData({
      RePassValue: params.detail.value
    })
  },
  changeV: function (params) {
    var reKey = params.currentTarget.dataset.id
    var that = this
    this.setData({
      ReKey: reKey,
      ReUser: false,
      ReValue: that.data.userInfo[reKey]
    })
  },
  changeName:function (params) {
    var reKey = params.currentTarget.dataset.id
    var that = this
    this.setData({
      ReKey: reKey,
      ReUserName: false,
      ReValue: that.data.userInfo[reKey]
    })
  },
  ReUserCandel: function () {
    // do something
    this.setData({
      ReUser:true,
      ReValue: ""
    })
  },

  /**
    *  点击确认
    */
   ReUserConfirm: function () {
    // do something
    this.setData({
      ReUser:true
    })
    var ReSet = "uid="+this.data.userInfo.userId+","+this.data.ReKey+"="+this.data.ReValue
    var that = this
    var dataget = wx.request({
      url: 'https://127.0.0.1:10270/api/userInfoReValue?ReSet='+ReSet,
      method: "post",
      timeout: 0,
      success: (result) => {
        console.log(result);
        wx.showModal({
         title: '操作执行结果',
         content: result.data,
         success: function (params) {
          that.onLoad()
         }
       })
       dataget.abort()
      },
    })
  },

  ReUserNameCandel: function () {
    // do something
    this.setData({
      ReUserName:true,
      ReValue: "",
      RePassValue: ""
    })
  },

  /**
    *  点击确认
    */
   ReUserNameConfirm: function () {
    // do something
    this.setData({
      ReUserName:true
    })

    var pass = this.data.RePassValue
    var passlist = pass.split("")
    var CharSelect = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
    var pwd2log = ""
    for (let index = 0; index < pass.length; index++) {
      var charindexof = CharSelect.indexOf(passlist[index])+11;
      if (charindexof > CharSelect.length) {
        charindexof = charindexof - CharSelect.length - 1
      }
      const element = CharSelect.charAt(charindexof);
        pwd2log +=  element
    }

    var ReSet = "uid="+this.data.userInfo.userId+","
                +this.data.ReKey+"="+this.data.ReValue
                +",RePass="+pwd2log
    var that = this
    var dataget = wx.request({
      url: 'https://127.0.0.1:10270/api/userInfoReValue?ReSet='+ReSet,
      method: "post",
      success: (result) => {
        console.log(result);
        wx.showModal({
         title: '操作执行结果',
         content: result.data,
         success: function (params) {
          that.onLoad()
         }
       })
       dataget.abort()
      },
    })
  },
  insertPageClick:function (params) {
    var key = params.currentTarget.dataset.index
    // console.log(key);
    wx.navigateTo({
        url: '../xinZengDan/order1/order?key='+key+'&userName='+this.data.userInfo.userName,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var that = this
    var userid = app.globalData.userId
    console.log(userid);
    var dataget = wx.request({
      url: 'https://127.0.0.1:10270/api/Return2WeiXin?userId='+userid+'&type=3',
      method: "post",
      timeout: 0,
      success: (result) => {
        that.setData({
          userInfo: result.data.user
        })
        console.log(that.data.userInfo);
        dataget.abort()
      },
    })
  },
  reLog:function () {
    wx.navigateBack({
      url: '/pages/index/index'
    })
  }
})
